package com.upcode.weighing.admin.controller.sys;


import com.upcode.weighing.base.controller.BaseController;
import com.upcode.weighing.domain.SysRole;
import com.upcode.weighing.log.OpsLog;
import com.upcode.weighing.service.SysRoleService;
import com.upcode.weighing.util.SecurityUtils;
import com.upcode.weighing.vo.req.pc.SysRoleReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author alex
 * @since 2019-03-10
 */
@RestController
@RequestMapping("/role")
@Api(value = "/role",description = "接口",produces = MediaType.ALL_VALUE)
public class SysRoleController extends BaseController {

    @Autowired
    SysRoleService roleService;
    @OpsLog(operation = "接口/列表查询/查询" ,type = 1)
    @PostMapping("/selectList")
    @ApiOperation(value = "列表查询",notes = "查询",httpMethod = "POST")
    public Object selectByList(@RequestBody SysRoleReqVo vo){
    	//如果登录账户是超级管理员，则返回全部，如果不是，返回对应角色
    	Long currentUserId = SecurityUtils.getCurrentUserId();
    	List<SysRole> userRole = roleService.getRoleByUser(currentUserId);
    	if(null != userRole && userRole.size()>0 && userRole.get(0).getName().equals("超级管理员")) {
            return success(roleService.list());
    	}else {
    		return success(userRole);
    	}
    }

}
